package com.education.platform.api.service.impl;

import com.education.platform.common.enums.FlowBusinessTypeEnum;
import com.education.platform.common.enums.FlowTypeEnum;
import com.education.platform.common.service.impl.BaseServiceImpl;
import com.education.platform.dao.entity.AccountDO;
import com.education.platform.dao.entity.AccountFlowDO;
import org.springframework.beans.factory.annotation.Autowired;
import com.education.platform.dao.AccountFlowDao;
import org.springframework.stereotype.Service;
import com.education.platform.api.service.AccountFlowService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.validation.constraints.NotNull;
import java.util.Date;

/**
* describe: 账户流水
* @author : tomato
* @date: 2020-06-06 02:55:52.219
**/
@Service
public class AccountFlowServiceImpl extends BaseServiceImpl<AccountFlowDao, AccountFlowDO> implements AccountFlowService {

	private static final Logger LOGGER = LoggerFactory.getLogger(AccountFlowServiceImpl.class);

    @Autowired
	private AccountFlowDao accountFlowDao;

    /**
     * 创建记录
     * @param accountDO
     * @param fbt
     * @param ft
     * @param flow
     */
    @Override
    public void createAccountFlow(AccountDO accountDO,  FlowBusinessTypeEnum fbt, FlowTypeEnum ft, Integer flow,String relationNo){
        AccountFlowDO accountFlowDO = new AccountFlowDO();
        accountFlowDO.setUserId(accountDO.getUserId());
        accountFlowDO.setFlowNumber(flow);
        accountFlowDO.setCreateTime(new Date());
        accountFlowDO.setDeleted(false);
        accountFlowDO.setBusinessType(fbt.getValue());
        accountFlowDO.setFlowType(ft.getValue());
        accountFlowDO.setRemarks(fbt.getDes());
        accountFlowDO.setBeforeNumber(accountDO.getBeanNumber());
        switch (ft){
            case IN:
                accountFlowDO.setAfterNumber(accountDO.getBeanNumber()+flow);
                break;
                case OUT:
                    accountFlowDO.setAfterNumber(accountDO.getBeanNumber()-flow);
                    break;
                }
        accountFlowDO.setRelationNo(relationNo);
        accountFlowDao.insert(accountFlowDO);
    }

}
